﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Gman.Entity.Entities;
using System.Collections.Generic;
using System.Web.Mvc;
using Gman.WebApp.ServiceControllers;


namespace Gman.WebApp.Models
{
    public class BienModel :BaseModel
    {        
        private OperacionServiceController service = new OperacionServiceController();        
        public ValidationBase Validator { get; set; }
        public List<KeyValuePair<string, string>> ValidationList = new List<KeyValuePair<string, string>>();
        public List<KeyValuePair<string, bool>> PropertyVisibilityList = new List<KeyValuePair<string, bool>>();

        #region create

        public BienBE Bien { get; private set; }
        public Guid? ID { get; set; }
        public string Action { get; set; }
        public ToolBarModel ToolBar { get; set; }
        
        public SelectList TipoBien { get; private set; }
        public SelectList Sedes { get; private set; }
        public SelectList Area { get; private set; }
        public SelectList Linea { get; private set; }
        public SelectList Garantia { get; private set; }
        public SelectList Contrato { get; private set; }
        public SelectList Proveedor { get; private set; }

        
        SedeBE sede = new SedeBE();
        ProveedorBE proveedor = new ProveedorBE();

        public BienModel(BienBE bien)
        {
            Bien = bien;
            ID = Guid.NewGuid();

            sede.IDEmp = 1;

            TipoBien = ListaTipoBien();
            Sedes = ListaSedes();
            Area = ListaAreas();
            Linea = ListaLineas();
            Garantia = ListaGarantias();
            Contrato = ListaContratos();
            Proveedor = ListaProveedores();
        }

        #endregion

        #region drop downs
        public SelectList ListaTipoBien()
        {
            List<SelectListItem> list = new List<SelectListItem>();

            list.Add(seleccione);
            list.Add(new SelectListItem() { Text = "Activo", Value = "1" });
            list.Add(new SelectListItem() { Text = "Sistema", Value = "2" });

            return new SelectList(list, "Value", "Text");
        }

        public SelectList ListaSedes()
        {
            sede.IDEmp = 1;
            List<SelectListItem> listItem = new List<SelectListItem>();

            listItem.Add(seleccione);
            listItem.AddRange(new SelectList(service.ListarSede(sede), "IDSede", "NomSede"));

            return new SelectList(listItem, "Value", "Text");
        }

        public SelectList ListaAreas()
        {
            List<SelectListItem> list = new List<SelectListItem>();

            list.Add(seleccione);
            list.Add(new SelectListItem() { Text = "Administracion", Value = "1" });
            list.Add(new SelectListItem() { Text = "Almacen", Value = "2" });
            list.Add(new SelectListItem() { Text = "RRHH", Value = "3" });

            return new SelectList(list, "Value", "Text");
        }

        public SelectList ListaLineas()
        {
            List<SelectListItem> list = new List<SelectListItem>();

            list.Add(seleccione);
            list.Add(new SelectListItem() { Text = "Sistema Electrico", Value = "1" });
            list.Add(new SelectListItem() { Text = "Sistema de Seguridad", Value = "2" });
            
            return new SelectList(list, "Value", "Text");
        }

        public SelectList ListaGarantias()
        {
            List<SelectListItem> list = new List<SelectListItem>();

            list.Add(seleccione);
            list.Add(new SelectListItem() { Text = "Si", Value = "1" });
            list.Add(new SelectListItem() { Text = "No", Value = "2" });

            return new SelectList(list, "Value", "Text");
        }

        public SelectList ListaContratos()
        {
            List<SelectListItem> list = new List<SelectListItem>();

            list.Add(seleccione);
            list.Add(new SelectListItem() { Text = "Soporte Tecnico", Value = "1" });
            list.Add(new SelectListItem() { Text = "Mantenimiento de Fallas", Value = "2" });

            return new SelectList(list, "Value", "Text");
        }
                
        public SelectList ListaProveedores()
        {
            List<SelectListItem> listItem = new List<SelectListItem>();

            //List<ProveedorBE> lista = new List<ProveedorBE>();
            //lista = service.ListProveedor(proveedor).ToList();
            listItem.Add(seleccione);
            listItem.AddRange(new SelectList(service.ListProveedor(proveedor), "IDProveedor", "RazonSProv"));

            return new SelectList(listItem, "Value", "Text");
        }
        #endregion
        
        public List<BienBE> ListaBien { get; private set; }

        public BienModel(IList<BienBE> bienes)
        {
            ListaBien = bienes.ToList();
        }     

    }
}
